Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add solution #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Pokhvalenkos
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job on implementing the server and HTML form! 🎉 While there are minor issues with the assumption that compressionType and file are arrays, the overall functionality meets the task requirements. Keep up the good work and consider verifying the data structure to enhance robustness in future projects. 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨

if (req.method === 'POST' && pathname === '/compress') {
const form = new formidable.IncomingForm();

form.parse(req, (error, { compressionType }, { file }) => {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compressionType and file are accessed as arrays (e.g., compressionType[0] and file[0]). Ensure that these variables are indeed arrays. If they are not, you should access them directly without indexing.

return;
}

if (!['gzip', 'deflate', 'br'].includes(compressionType[0])) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check for compressionType[0] assumes compressionType is an array. Verify that compressionType is an array. If not, adjust the code to handle it correctly.


res.setHeader(
'Content-Disposition',
`attachment; filename=${file[0].originalFilename}.${compressionType[0]}`,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file[0].originalFilename assumes file is an array. Ensure that file is indeed an array. If not, adjust the code to access the filename correctly.

`attachment; filename=${file[0].originalFilename}.${compressionType[0]}`,
);

const fileStream = fs.createReadStream(file[0].filepath);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The file[0].filepath assumes file is an array. Verify that file is an array. If not, adjust the code to access the filepath correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants